package org.nf.shopping.controller;

import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.nf.shopping.common.vo.ResultVO;
import org.nf.shopping.entity.Admin;
import org.nf.shopping.service.AdminService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author czl
 * @Date 2024-12-01
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin")
public class AdminController extends BaseController{

    private final AdminService adminService;

    @GetMapping("/listAdmin")
    public ResultVO<PageInfo<Admin>> listAdmin(Integer limit, Integer page, String name){
        PageInfo<Admin> pageInfo = adminService.listAdmin(limit, page, name);
        return success(pageInfo);
    }

    @PostMapping("/updateAdmin")
    public ResultVO updateAdmin(Admin admin){
        adminService.updateAdmin(admin);
        return success();
    }

    @PostMapping("/deloneAdmin")
    public ResultVO deloneAdmin(Integer id){
        adminService.deloneAdmin(id);
        return success();
    }

    @PostMapping("/addAdmin")
    public ResultVO addAdmin(Admin admin){
        adminService.addAdmin(admin);
        return success();
    }

    @PostMapping("/getAdminList")
    public ResultVO<List<Admin>> getAdminList(){
        return success(adminService.getAdminList());
    }

}
